const express = require('express');
const asyncHandler = require('express-async-handler');
const basicController = require('../controllers/basic.controller')
const router = express.Router();
module.exports = router;

//根据搜索内容获取对应的安全事件
router.post('/getSafetyViolationByDuration', asyncHandler(getSafetyViolationByDuration))

//获取安全信息统计信息
router.post('/getSafetyInfoByDuration', asyncHandler(getSafetyInfoByDuration))

//删除安全事件
router.post('/deleteSafetyViolation', asyncHandler(deleteSafetyViolation))

//人员履职
router.post('/getPPLCountByDuration', asyncHandler(getPPLCountByDuration))

async function getSafetyViolationByDuration(req, res) {
    let result = await basicController.getSafetyViolationByDuration(req.body)
    res.json(result)
}

async function getSafetyInfoByDuration(req, res) {
    let result = await basicController.getBasicInfoByDuration(req.body, 'safety_violation')
    res.json(result)
}

async function deleteSafetyViolation(req, res) {
    let result = await basicController.deleteViolationData(req.body, 'safety')
    res.json(result)
}

async function getPPLCountByDuration(req, res) {
    let result = await basicController.getEventsWithTypeByDuration(req.body, 'ppl_count')
    res.json(result)
}